package com.groupnections.client.Entities;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.groupnections.client.utilities.FormField;
import com.groupnections.shared.Entity;

public class EditEntity extends VerticalPanel {

	public static TextBox entityName = new TextBox();

	public static TextBox entityImage = new TextBox();

	public EditEntity(Entity entity) {

		Label entityID = new Label(entity.getEntityID());
		this.add(FormField.getFormField("ID", entityID));

		entityName.setValue(entity.getEntityName());
		this.add(FormField.getFormField("Name", entityName));

		this.add(saveEntity(entity));
	}

	public Button saveEntity(final Entity entity) {

		Button save = new Button("Save");

		save.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				entity.setEntityName(entityName.getValue());

				new UpdateEntity(entity);
			}
		});

		return save;
	}
}
